#include "arguments.h"
#include "error.h"

#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>

int port    = 7;
int daemond = 0;
int optp;

static struct option opt[] = {
    {"port",   1, 0, 'p'},
    {"daemon", 0, 0, 'd'},
    {"help",   0, 0, 'h'},
    {0,0,0,0}
};
void usage(int argc, char **argv)
{
    err_msg("usage: %s [option[=value]]...", argv[0]);
    err_msg("  -p, --port=number       default port 7");
    err_msg("  -d, --daemon            daemon mode");
    err_msg("  -h, --help              usage help");
}
void arguments(int argc, char **argv)
{
    char c;
    opterr = 1;
    while ((c = getopt_long(argc,argv,"p:dh", opt, 0)) != -1) {
        switch (c) {
            case 'p': 
                optp = 1;
                port = atoi(optarg);
                break;
            case 'd': 
                daemond = 1;
                break;
            case 'h': 
                usage(argc, argv);
                exit(0);
            case '?':
                err_quit("Try '%s --help' for more information.", argv[0]);
            default :
                usage(argc, argv);
                exit(1);
        }
    }
}

